<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>热更新 | RobotJs | 用JS任意控制手机上的APP</title>
  <link rel="stylesheet" href="assets/fonts.css">
  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/sh.css">
  <link rel="canonical" href="https://nodejs.org/api/patchs.html">
</head>
<body class="alt apidoc" id="api-section-patchs">
  <div id="content" class="clearfix">
    <div id="column2" class="interior">
      <div id="intro" class="interior">
        <a href="/" title="返回首页">
          RobotJs
        </a>
      </div>
      <ul>
<li><a class="nav-startnow" href="startnow.html">开始</a></li>
<li><a class="nav-hbuilder" href="hbuilder.html">Demo, 调试运行</a></li>
<li><a class="nav-hello" href="hello.html">Hello World</a></li>
<li><a class="nav-autojs-vue" href="autojs-vue.html">与vue交互</a></li>
<li><a class="nav-normal" href="normal.html">常用api</a></li>
<li><a class="nav-links" href="links.html">支持库(超强)</a></li>
<li><a class="nav-patchs active" href="patchs.html">热更新</a></li>
<li><a class="nav-deploy" href="deploy.html">打包</a></li>
<li><a class="nav-remote" href="remote.html">远程部署</a></li>
<li><a class="nav-java" href="java.html">与java交互</a></li>
<li><a class="nav-qa" href="qa.html">Q&amp;A - 常见问题</a></li>
<li><a class="nav-https-miren-lovemi-ren-colorui-document-" href="https://miren.lovemi.ren/colorui-document/" target="_blank" rel="noopener noreferrer">UI设计</a><div class="line"></div></li>
<li><a class="nav--" href="#">【API文档】:</a></li>
<li><a class="nav-overview" href="overview.html">Overview - 综述</a></li>
<li><a class="nav-documentation" href="documentation.html">Tip - 阅读说明</a></li>
<li><a class="nav-coordinatesBasedAutomation" href="coordinatesBasedAutomation.html">Click - 基于坐标的操作</a></li>
<li><a class="nav-widgetsBasedAutomation" href="widgetsBasedAutomation.html">开始 - 基于控件的操作</a></li>
<li><a class="nav-widgetsBasedAutomation-widgetsbasedautomation_simpleactionautomator" href="widgetsBasedAutomation.html#widgetsbasedautomation_simpleactionautomator">Click - 基于控件的操作</a></li>
<li><a class="nav-widgetsBasedAutomation-widgetsbasedautomation_uiselector" href="widgetsBasedAutomation.html#widgetsbasedautomation_uiselector">UiSelector - 查找控件</a></li>
<li><a class="nav-widgetsBasedAutomation-widgetsbasedautomation_uiobject" href="widgetsBasedAutomation.html#widgetsbasedautomation_uiobject">UiObject - 控件</a></li>
<li><a class="nav-app" href="app.html">App - 应用</a></li>
<li><a class="nav-canvas" href="canvas.html">Canvas - 画布</a></li>
<li><a class="nav-console" href="console.html">Console - 控制台</a></li>
<li><a class="nav-crypto" href="crypto.html">Crypto - 加解密与消息摘要</a></li>
<li><a class="nav-device" href="device.html">Device - 设备</a></li>
<li><a class="nav-dialogs" href="dialogs.html">Dialogs - 对话框</a></li>
<li><a class="nav-engines" href="engines.html">Engines - 脚本引擎</a></li>
<li><a class="nav-events" href="events.html">Events - 事件与监听</a></li>
<li><a class="nav-floaty" href="floaty.html">Floaty - 悬浮窗</a></li>
<li><a class="nav-files" href="files.html">Files - 文件系统</a></li>
<li><a class="nav-globals" href="globals.html">Globals - 一般全局函数</a></li>
<li><a class="nav-http" href="http.html">Http - HTTP</a></li>
<li><a class="nav-images" href="images.html">Images - 图片与图色处理</a></li>
<li><a class="nav-keys" href="keys.html">Keys - 按键模拟</a></li>
<li><a class="nav-media" href="media.html">Media - 多媒体</a></li>
<li><a class="nav-modules" href="modules.html">Modules - 模块</a></li>
<li><a class="nav-sensors" href="sensors.html">Sensors - 传感器</a></li>
<li><a class="nav-shell" href="shell.html">Shell - Shell命令</a></li>
<li><a class="nav-storages" href="storages.html">Storages - 本地存储</a></li>
<li><a class="nav-threads" href="threads.html">Threads - 多线程</a></li>
<li><a class="nav-timers" href="timers.html">Timers - 定时器</a></li>
<li><a class="nav-ui" href="ui.html">UI - 用户界面</a></li>
<li><a class="nav-https-developer-mozilla-org-zh-CN-docs-Mozilla-Projects-Rhino-Scripting_Java" href="https://developer.mozilla.org/zh-CN/docs/Mozilla/Projects/Rhino/Scripting_Java">Work with Java - 调用Java API</a></li>
</ul>
<div class="line"></div>



    </div>

    <div id="column1" data-id="patchs" class="interior">
      <header>
        <h1>用JS任意控制手机上的APP</h1>
        <div id="gtoc">
          <p>
            <a href="index.html" name="toc">索引</a> |
            <a href="all.html">查看全部</a>
          </p>
        </div>
        <hr>
      </header>

      <div id="toc">
        <h2>目录</h2>
        <ul>
<li><span class="stability_undefined"><a href="#patchs">热更新</a></span><ul>
<li><span class="stability_undefined"><a href="#patchs_0">0. 准备补丁</a></span><ul>
<li><span class="stability_undefined"><a href="#patchs_hbuiderx">HbuiderX生成加密的补丁文件</a></span><ul>
<li><span class="stability_undefined"><a href="#patchs_1_hbuiderx_app"><code>[步骤]</code>1. HbuiderX菜单 -&gt; 发行 -&gt; 本地打包 -&gt; 生成app资源</a></span></li>
<li><span class="stability_undefined"><a href="#patchs_2_hbuiderx_3"><code>[步骤]</code>2. HbuiderX菜单 -&gt; 运行 -&gt; 运行到终端 -&gt; 3.生成热补丁</a></span></li>
</ul>
</li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#patchs_1">1. 自动升级(快捷）</a></span></li>
<li><span class="stability_undefined"><a href="#patchs_2">2. 先 检查, 然后升级</a></span><ul>
<li><span class="stability_undefined"><a href="#patchs_1">界面代码</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#patchs_3">3. 存储热补丁到自定义服务器</a></span><ul>
<li><span class="stability_undefined"><a href="#patchs_2">.</a></span></li>
</ul>
</li>
</ul>
</li>
</ul>

      </div>

      <div id="apicontent">
        <h1>热更新<span><a class="mark" href="#patchs" id="patchs">#</a></span></h1>
<h2>0. 准备补丁<span><a class="mark" href="#patchs_0" id="patchs_0">#</a></span></h2>
<h3>HbuiderX生成加密的补丁文件<span><a class="mark" href="#patchs_hbuiderx" id="patchs_hbuiderx">#</a></span></h3>
<p>修改manifest.json文件的版本号</p>
<h4><code>[步骤]</code>1. HbuiderX菜单 -&gt; 发行 -&gt; 本地打包 -&gt; 生成app资源<span><a class="mark" href="#patchs_1_hbuiderx_app" id="patchs_1_hbuiderx_app">#</a></span></h4>
<h4><code>[步骤]</code>2. HbuiderX菜单 -&gt; 运行 -&gt; 运行到终端 -&gt; 3.生成热补丁<span><a class="mark" href="#patchs_2_hbuiderx_3" id="patchs_2_hbuiderx_3">#</a></span></h4>
<h2>1. 自动升级(快捷）<span><a class="mark" href="#patchs_1" id="patchs_1">#</a></span></h2>
<div class="signature"><ul>
<li>在你的VUE项目中，加入如下代码；</li>
<li>那么当你的程序执行到这个代码的时候，你的APP应用，就会检查并自动升级。</li>
</ul>
</div><pre><code class="lang-js">// 检查,直接升级
const {version} = require(&#39;robot-tools&#39;); 

version.onReady = () =&gt; { 
    version.checkThenInstall();
};

</code></pre>
<p>参数：</p>
<pre><code class="lang-js">const {version} = require(&#39;robot-tools&#39;);
version.checkThenInstall();  //检查并自动升级，有提示文字
version.checkThenInstall(&#39;加载中...&#39;);  //修改加载提示文字
version.checkThenInstall(false);   //无加载提示， 等于version.install();

//非debug环境(调试基座)才升级
if(version.isDebug == false){
    version.checkThenInstall(); 
};

</code></pre>
<h2>2. 先 检查, 然后升级<span><a class="mark" href="#patchs_2" id="patchs_2">#</a></span></h2>
<h3>界面代码<span><a class="mark" href="#patchs_1" id="patchs_1">#</a></span></h3>
<pre><code class="lang-html">&lt;template&gt; 
    &lt;view class=&quot;cu-load load-modal&quot; v-if=&quot;loadingModal&quot;&gt; 
        &lt;image src=&quot;/static/logo.png&quot; mode=&quot;aspectFit&quot;&gt;&lt;/image&gt;
        &lt;view class=&quot;gray-text&quot;&gt;{{LoadingText}}&lt;/view&gt;
    &lt;/view&gt;
    &lt;text&gt;当前版本: {{currentVersion}}&lt;/text&gt;
    &lt;text&gt;远程版本: {{remoteVersion}}&lt;/text&gt;
    &lt;button class=&quot;cu-btn bg-green shadow&quot; @tap=&quot;upgrade&quot;&gt;点我升级&lt;/button&gt;
&lt;/template&gt;
</code></pre>
<p>检查代码</p>
<pre><code class="lang-js">const {version, project} = require(&#39;robot-tools&#39;);

export default {
    data:   {loadingModal: false, currentVersion:&#39;0.0.0&#39;,remoteVersion:&#39;&#39;},
    created: function() {
        var that = this;
        this.currentVersion = version.name;

        console.log(&quot;开始检查---&gt;&quot;);
        version.checkVersion((res) =&gt; { 
            that.remoteVersion = res.version;
            if (version.name != res.version) {
                console.log(&#39;需要升级&#39;);
            } else {
                console.log(&#39;不升级&#39;);
            }
        });
    },
    methods:{
       upgrade: function() {
            console.log(&quot;开始升级---&gt;&quot;);
            this.loadingModal = true;
            this.LoadingText = &#39;升级中..&#39;;
            version.install((status) =&gt; {
                this.loadingModal = false;
            });
        } 
    }
};

</code></pre>
<h2>3. 存储热补丁到自定义服务器<span><a class="mark" href="#patchs_3" id="patchs_3">#</a></span></h2>
<p>自定义服务器，请参考 <a href="https://gitee.com/vnool/robot-tools">内核与打包</a></p>
<h3>.<span><a class="mark" href="#patchs_2" id="patchs_2">#</a></span></h3>
<p>⚠️ 提示：APPID，版本号 ⚠️</p>
<pre><code>const {version, project} = require(&#39;robot-tools&#39;);

A. project.manifest.id;  // 你代码的id (manifest里的)
A. project.manifest.appid; 
A. project.manifest.version.name; //你代码的版本号
A. project.manifest.version.code;
A. project.manifest; //打印一下看看
A. version.name;  //你代码的版本号 (manifest里的)

//----⚠️ 请用A，不要用B ⚠️----

B. plus.runtime.appid;
B. plus.runtime.versionCode;   //基座版本号(整数)
B. plus.runtime.version;      //基座版本号
B. plus.runtime.innerVersion;
B. plus.runtime.uniVersion;

// A是manifest.json里的内容
// B是基座的信息（调试环境和正式环境，信息不同）
// ⚠️ 请用A，不要用B ⚠️ 
</code></pre>
      </div>
    </div>
  </div>
  <script src="assets/sh_main.js"></script>
  <script src="assets/sh_javascript.min.js"></script>
  <script>highlight(undefined, undefined, 'pre');</script>
  <!-- __TRACKING__ -->
</body>
</html>